package com.liuyu2783.redislock.exception;

import com.liuyu2783.redislock.common.MyResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * com.liuyu2783.redislock.exception
 *
 * @author liuyu07
 * @date 2019-6-28
 */
@ControllerAdvice
public class RedisLockExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(RedisLockExceptionHandler.class);

    @ResponseBody
    @ExceptionHandler(RedisLockException.class)
    public MyResponse exceptionResult(RedisLockException redisLockException){
        logger.warn("自定义异常捕捉, {}",redisLockException.toString());
        MyResponse myResponse = new MyResponse(redisLockException.getCode(),redisLockException.getMessage());
        return myResponse;
    }

}
